package com.yanze.schoolinformation.adapter.rv;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

import com.yanze.schoolinformation.R;
import com.yanze.schoolinformation.base.baseadapter.BaseRecyclerViewAdapter;
import com.yanze.schoolinformation.base.baseadapter.BaseRecyclerViewHolder;
import com.yanze.schoolinformation.databinding.ItemBookBinding;
import com.yanze.schoolinformation.model.bean.book.BooksBean;
import com.yanze.schoolinformation.utils.PerfectClickListener;
import com.yanze.schoolinformation.utils.ToastUtils;
import com.yanze.schoolinformation.view.information.book.BookDetailActivity;

/**
 * Created by MrZheng on 2018/4/27.
 */

public class BookListAdapter extends BaseRecyclerViewAdapter<BooksBean> {
    private Activity activity;

    public BookListAdapter(Activity activity) {
        this.activity = activity;
    }

    @NonNull
    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(parent, R.layout.item_book);
    }

    private class ViewHolder extends BaseRecyclerViewHolder<BooksBean, ItemBookBinding> {
        public ViewHolder(ViewGroup viewGroup, int layoutId) {
            super(viewGroup, layoutId);
        }

        @Override
        public void onBindViewHolder(BooksBean bookBean, final int position) {
            if (bookBean != null) {
                binding.setBean(bookBean);
                binding.executePendingBindings();

                binding.llItemTop.setOnClickListener(new PerfectClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {
                        BookDetailActivity.start(activity,data.get(position),binding.ivTopPhoto);
                    }
                });
            }
        }
    }
}
